#!/bin/sh
#desc:Changes the previous song as the current
#package:odbgmusic
#type:local

CONFILE=/etc/opendomo/music.conf
. $CONFILE

# Check there are songs in played
if test "" != "`cat $TMPPLAYED`"; then
        rm -f $TMPPENDINGAUX
        touch $TMPPENDINGAUX
	chown admin:admin $TMPPENDINGAUX
        chmod a+w $TMPPENDINGAUX

        # Move the current song to the first in pending
        echo "`cat $TMPCURRENT`"        > $TMPPENDINGAUX
        echo "`cat $TMPPENDING`"        >> $TMPPENDINGAUX
        mv $TMPPENDINGAUX $TMPPENDING

        # Move the las in played to current
        echo "`cat $TMPPLAYED | tail -1`"       > $TMPCURRENT

        # Erase the last in played
        echo "`cat $TMPPLAYED | sed '$d'`" > $TMPPLAYED
else
        echo "#INFO No previously played songs"
fi

# Always return to bgmusic web controler

/usr/local/opendomo/bgmusicControl.sh

